#include "../Tools/GLHeaders.hpp"
#include "ModelHead.hpp"
#include <cmath>

ModelHead::ModelHead(void){
	activate = false;	
  list_id = glGenLists(1); // create one DisplayList
  glNewList(list_id, GL_COMPILE);
 	GLUquadricObj *quadratic = gluNewQuadric();
  gluQuadricNormals(quadratic, GLU_SMOOTH);

 GLfloat pt00[] = { 1.0f,-0.5f , 1.5f};
  GLfloat pt01[] = { 1.0f,-0.5f , 1.0f};
  GLfloat pt02[] = { 1.0f, 0.25f, 0.625f};
  GLfloat pt03[] = { 1.0f, 0.5f ,-0.5f};
  GLfloat pt04[] = { 1.0f, 1.5f ,-0.5f};
  GLfloat pt05[] = { 1.0f, 2.0f , 0.25f};
  GLfloat pt06[] = { 1.0f, 2.0f , 1.25f};
  GLfloat pt07[] = { 1.0f, 1.5f , 2.0f};
  GLfloat pt08[] = { 1.0f, 0.5f , 2.0f};

  GLfloat pt10[] = {-1.0f,-0.5f , 1.5f};
  GLfloat pt11[] = {-1.0f,-0.5f , 1.0f};
  GLfloat pt12[] = {-1.0f, 0.25f, 0.625f};
  GLfloat pt13[] = {-1.0f, 0.5f ,-0.5f};
  GLfloat pt14[] = {-1.0f, 1.5f ,-0.5f};
  GLfloat pt15[] = {-1.0f, 2.0f , 0.25f};
  GLfloat pt16[] = {-1.0f, 2.0f , 1.25f};
  GLfloat pt17[] = {-1.0f, 1.5f , 2.0f};
  GLfloat pt18[] = {-1.0f, 0.5f , 2.0f};
  glBegin(GL_TRIANGLES);
  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // Front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt08);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt08);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  
  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12); // Back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt18);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt18);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  
  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01); // Bottom
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  
  glNormal3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06); // Top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  
  glNormal3f( 0.0f, sinf(M_PI/4.0f),-cosf(M_PI/4.0f));
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);// Right Top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);

  glNormal3f(0.0f, sinf(3.0f*M_PI/4.0f),-cos(3.0f*M_PI/4.0f));
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);// Left Top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);

  glNormal3f( 0.0f, 0.0f, 1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt18);// Left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt08);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt18);
  
  glNormal3f( 0.0f, 0.0f,-1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03); // Right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  
  glNormal3f(0.0f, sinf(-M_PI/3.0f),-cos(-M_PI/3.0f));
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // Right Bottom (upper)
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);

  glNormal3f(0.0f, sinf(-M_PI/6.0f),-cos(-M_PI/6.0f));
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01); // Right Bottom (down)
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);

  glNormal3f(0.0f, sinf(-5.0f*M_PI/6.0f),-cos(-5.0f*M_PI/6.0f)); 
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10); // Left Bottom
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt08);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt08);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt18);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glEnd();
  glEndList();
 }

ModelHead::~ModelHead(void){
  glDeleteLists(list_id,1);
}

void ModelHead::Draw(void){
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_TEXTURE_BIT);	
	glDisable(GL_TEXTURE_2D); 
	if(activate)
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	else
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

  glCallList(list_id);
	glPopAttrib();
}

void ModelHead::Activate(void){
	activate = true;
}

void ModelHead::Desactivate(void){
	activate = false;
}
